﻿<%@ Page Language="C#" MasterPageFile="~/ExampleMaster.Master" AutoEventWireup="true"
    CodeBehind="Count.aspx.cs" Inherits="Web.Samples.Count" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleZone" runat="server">
    Counting with the Framework and LINQ
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="IntroTextZone" runat="server">
    LINQ can be used to count items in a collection, a filter can be applied to perform
    a conditional count
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="QueryExpressZone" runat="server">
    <pre class="code">            <span style="color: rgb(0,0,255)">var</span> query = <span
        style="color: rgb(0,0,255)">from</span> p <span style="color: rgb(0,0,255)">in</span> <span
            style="color: rgb(43,145,175)">Product</span>.GetProducts()
                        <span style="color: rgb(0,0,255)">select</span> p;

            <span style="color: rgb(0,0,255)">this</span>.litQueryResults.Text = <span style="color: rgb(0,0,255)">string</span>.Format(<span
                style="color: rgb(163,21,21)">"Total Items: {0}&lt;br /&gt;\n"</span>, query.Count());
            <span style="color: rgb(0,0,255)">this</span>.litQueryResults.Text += <span style="color: rgb(0,0,255)">string</span>.Format(<span
                style="color: rgb(163,21,21)">"Total Items starting with 'A': {0}"</span>, query.Count(p =&gt; p.Name.StartsWith(<span
                    style="color: rgb(163,21,21)">"A"</span>)));</pre>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="QueryResultsZone" runat="server">
    <asp:Literal ID="litQueryResults" runat="server" />
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ImperativeZone" runat="server">
    <pre class="code">            <span style="color: rgb(0,0,255)">this</span>.litImperativeResults.Text = <span
        style="color: rgb(0,0,255)">string</span>.Format(<span style="color: rgb(163,21,21)">"Total
            Items: {0}&lt;br /&gt;\n"</span>, <span style="color: rgb(43,145,175)">Product</span>.GetProducts().Count());
            <span style="color: rgb(0,0,255)">this</span>.litImperativeResults.Text += <span
                style="color: rgb(0,0,255)">string</span>.Format(<span style="color: rgb(163,21,21)">"Total
                    Items starting with 'A': {0}&lt;br /&gt;\n"</span>, <span style="color: rgb(43,145,175)">Product</span>.GetProducts().Count(p =&gt; p.Name.StartsWith(<span
                        style="color: rgb(163,21,21)">"A"</span>)));</pre>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="ImperativeResultsZone" runat="server">
    <asp:Literal ID="litImperativeResults" runat="server" />
</asp:Content>
